class Album < ActiveRecord::Base
  belongs_to :documet_type
  belongs_to :author,
    :class_name => "Valleyer",
    :foreign_key => "author_id",
    :counter_cache => true
  
  has_many :photos,
    :order => "created_at desc"
  has_many :post_sessions,
    :order => "created_at desc"

  #系统中最新的相册
  #根据updated_at
  def self.up_to_date_albums(args = {:last => 5})
    Album.all :order => "updated_at desc",
      :limit => args[:last]
  end

  #相册的最新相片
  def new_photo_of_the_album
    Photo.first :conditions => ["album_id = ?", id], :order => "created_at desc"
  end

  #相册背景选择的API
  #如果7天内有添加新相片 true
  #否者 false
  def new?    
    created_at >= 7.days.ago
  end
end
